<template>
	<om-formsub-outer :index="index"  :confirmBtn="!checkedit" :checkedit="checkedit">
		<om-autoform ref="autoform" :checkedit="checkedit" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {subOnLoad, changeEditor,configSelectData} from '../../../static/js/formUtil.js';
	import urlUtil from '@/static/js/urlUtil.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return {
				checkedit:false,
				initValue:{
					userId:"",
					userName:"",
					postId:"",
					postName:""
				},
				autoformdata: [],
				cachename:'',
				index:null,
				datas:[],
				order:0,
				formdata:{},
				projectId:"",
				fileNameCacheKey:"adm-meet-summary-data-info-title5-dutyoff-cache",
			}
		},
		methods: {
			initLoad(){
				let _that = this
				changeEditor('title6', "fileName", {
					"link":"/pages/public/search/search",
					"linkParam": {
						other:JSON.stringify({
							createProjectShowId:_that.projectId
						}),
						namefield:"nodeName",
						notefield:'retainFileJoinName',
						// searchfield:"q",
						initload:true,
						url:'createProjectShow/findFileList',
						cachename:_that.fileNameCacheKey,
						placeholder:"请输入过程阶段、交付物名称"
					}
				},null,_that.autoformdata)
				changeEditor(_that.autoformdata[0].editors, "fileList", "fileUploadKey", "13")
				if(_that.formdata.fileList) {
					var tempFileList = []
					var fileUrlList = _that.formdata.fileList.map(t=>{
						tempFileList.push(t.fileSaveName)
						return t.fileSaveName
					})
					changeEditor(_that.autoformdata[0].editors, "fileList", "fileUrlList", fileUrlList)
					changeEditor(_that.autoformdata[0].editors, "fileList", "tempFileList", tempFileList)
				}
			}
		},
		onLoad(e){
			//评审所需提供的交付物信息
			let _that = this
			subOnLoad(_that, e, function() {
				_that.projectId = e.projectId
				if(e.configDataCacheKey){
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if(res.data && res.data instanceof Array){
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
								Object.assign(_that.initValue, _that.formdata)
								_that.autoformdata[0].order = _that.order
								_that.initLoad()
							}
						}
					});
				}
			})
		},
		onShow(){
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key: this.fileNameCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							formdata.fileName = d.retainFileJoinName
							uni.removeStorage({
								key: _that.fileNameCacheKey
							});
						}
					}
				});
			}
		}
	}
</script>
